package dataStructure.chapter06_树.part1二叉树.binarysearchtree2;


/**
 * @author https://gitee.com/W_Jun
 * @date 2022-03-09 15:04
 * @Description
 */
public class TestBinarySearchTree {
    public static void main(String[] args) {
        Integer data[] = new Integer[] {7, 4, 9, 2, 5, 8, 11,3};
        BinarySearchTree<Integer> bst = new BinarySearchTree<>();
        for (int i = 0; i < data.length; i++) {
            bst.add(data[i]);
        }

        //原来写死的逻辑如打印 在使用的时候具体实现
        bst.levelOrder(new BinarySearchTree.Visitor<Integer>() {
            @Override
            public void visit(Integer element) {
                System.out.print("_" + element +" ");
            }
        });

        //前序
/*        bst.preorder(new BinarySearchTree.Visitor<Integer>() {
            @Override
            public void visit(Integer element) {
                System.out.print("_" + element +" ");
            }

        });*/

        //中序
/*        bst.inorder(new BinarySearchTree.Visitor<Integer>() {
            @Override
            public void visit(Integer element) {
                System.out.print("_" + element +" ");
            }

        });*/

        //后序
/*        bst.postorder(new BinarySearchTree.Visitor<Integer>() {
            @Override
            public void visit(Integer element) {
                System.out.print("_" + element +" ");
            }

        });*/


        //打印测试
        System.out.println();
        System.out.println("================");
        System.out.println(bst);

        //高度测试
        System.out.println("递归计算二叉树高度为：" + bst.height());
        System.out.println("迭代计算二叉树高度为：" + bst.high());

        //测试完全二叉树的判断
        //Integer[] data2 = new Integer[] {7, 4, 9, 2, 5};//是完全二叉树
        Integer[] data2 = new Integer[] {7, 4, 9, 2, 1};//不是完全二叉树
        BinarySearchTree<Integer> tree = new BinarySearchTree<>();
        for (int i = 0; i < data2.length; i++) {
            tree.add(data2[i]);
        }
        System.out.println(tree.isComplete());

        System.out.println("=========");
        //bst.invertTree();//前序实现翻转
        //bst.invertTreeInorder();//中序实现翻转
        bst.invertTreePostorder();
        bst.invertTreeLevelorder();//层序实现翻转
        System.out.println(bst);
    }
}
